package com.gzsxy.excel.dropDownListHandler;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.util.CellRangeAddressList;

/**
 * @Author
 * @Description //TODO Excel模板对象
 * @Date 2022/01/14
 * @Param $
 * @return $
 **/
public class SysUserSheetWriteHandler implements SheetWriteHandler {

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        CellRangeAddressList list1=new CellRangeAddressList(1,1000,4,4); //1到1000行、2到3列添加下拉框
        DataValidationHelper helper1=writeSheetHolder.getSheet().getDataValidationHelper();
        DataValidationConstraint constraint1=helper1.createExplicitListConstraint(new String[]{"其他","初中及以下","中专","高中","大专","本科","硕士","博士"});
        DataValidation dataValidation=helper1.createValidation(constraint1,list1);
        writeSheetHolder.getSheet().addValidationData(dataValidation);

        CellRangeAddressList list2=new CellRangeAddressList(1,1000,8,8);
        DataValidationHelper helper2=writeSheetHolder.getSheet().getDataValidationHelper();
        DataValidationConstraint constraint2=helper2.createExplicitListConstraint(new String[]{"领导","部门经理","副经理","主管","普通员工","实习生","其他"});
        DataValidation dataValidation2=helper2.createValidation(constraint2,list2);
        writeSheetHolder.getSheet().addValidationData(dataValidation2);

        CellRangeAddressList list3=new CellRangeAddressList(1,1000,200,200);
        DataValidationHelper helper3=writeSheetHolder.getSheet().getDataValidationHelper();
        DataValidationConstraint constraint3=helper3.createExplicitListConstraint(new String[]{"在职","离职","调休","其他"});
        DataValidation dataValidation3=helper3.createValidation(constraint3,list3);
        writeSheetHolder.getSheet().addValidationData(dataValidation3);

        CellRangeAddressList list4=new CellRangeAddressList(1,1000,9,9);
        DataValidationHelper helper4=writeSheetHolder.getSheet().getDataValidationHelper();
        DataValidationConstraint constraint4=helper4.createExplicitListConstraint(new String[]{"JAVA","C++","前端","Android","其他"});
        DataValidation dataValidation4=helper4.createValidation(constraint4,list4);
        writeSheetHolder.getSheet().addValidationData(dataValidation4);

        CellRangeAddressList list5=new CellRangeAddressList(1,1000,106,106);
        DataValidationHelper helper5=writeSheetHolder.getSheet().getDataValidationHelper();
        DataValidationConstraint constraint5=helper5.createExplicitListConstraint(new String[]{"管理员","研发第一负责人","研发第二负责人","研发人员"});
        DataValidation dataValidation5=helper5.createValidation(constraint5,list5);
        writeSheetHolder.getSheet().addValidationData(dataValidation5);
    }
}